//
//  NetRequestWithCahce.h
//  why
//
//  Created by Yinjialiang on 16/1/27.
//  Copyright © 2016年 刘赞黄Telen. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
typedef enum : NSUInteger {
    RequestType_Get = 0,
    RequestType_Post = 1,
}RequestType;

typedef enum : NSUInteger{
    TimeLimited_None = 0,
    TimeLimitedFive_Minutes = 1,
}TimeLimitedType;


@interface NetRequestWithCahce : NSObject

//用来记录应用启动后各个接口有没有请求过
@property (nonatomic,strong)NSMutableArray *portKeysArray;

@property (nonatomic,strong)NSURLSessionDataTask *lastTask;

+(NetRequestWithCahce *)shareSingle;

//单纯网络请求
-(void)netRequestWithType:(RequestType)requestType Port:(NSString*)port andBaseUrl:(NSString*)baseUrl parameters:(NSDictionary*)dict success:(void (^)(NSDictionary* retDict))success failure:(void (^)(NSError *error))failure;

//单纯网络请求(适配PEP请求格式)
-(void)netRequestWithJsonParamsType:(RequestType)requestType Port:(NSString*)port andBaseUrl:(NSString*)baseUrl parameters:(NSDictionary*)dict success:(void (^)(NSDictionary* retDict))success failure:(void (^)(NSError *error))failure;


//带缓存的网络请求
-(void)netRequestWithCacheType:(RequestType)requestType Port:(NSString *)port baseUrl:(NSString *)baseUrl parameters:(NSDictionary*)dict  keyID:(NSString *)keyId successAndIsNeedCache:(BOOL (^)(NSDictionary* retDict,BOOL hasCache))successAndCache failure:(void (^)(NSError *error,BOOL hasCache))failure cache:(void (^)(NSDictionary * cacheRetDict))cacheBack timeOut:(CGFloat)timeOut;

//带缓存的网络请求(适配PEP请求格式)
-(void)netRequestIsJsonParamsWithCacheType:(RequestType)requestType Port:(NSString *)port baseUrl:(NSString *)baseUrl parameters:(NSDictionary*)dict  keyID:(NSString *)keyId successAndIsNeedCache:(BOOL (^)(NSDictionary* retDict,BOOL hasCache))successAndCache failure:(void (^)(NSError *error,BOOL hasCache))failure cache:(void (^)(NSDictionary * cacheRetDict))cacheBack timeOut:(CGFloat)timeOut;


//requestType 请求方式
//keyId  缓存的标示
//isNeedCache  是否启用缓存(NO时 cacheBack返回空)
//timeOut  请求超时上限
//limitedSeconds 多长时间内不重复请求网络(单位:秒) 0默认不限制
-(void)netRequestWithCacheType:(RequestType)requestType Port:(NSString *)port baseUrl:(NSString *)baseUrl parameters:(NSDictionary*)dict  keyID:(NSString *)keyId successAndIsNeedCache:(BOOL (^)(NSDictionary* retDict,BOOL hasCache))successAndCache failure:(void (^)(NSError *error,BOOL hasCache))failure cache:(void (^)(NSDictionary * cacheRetDict))cacheBack timeOut:(CGFloat)timeOut timeLimitedType:(TimeLimitedType)timeLimitedType ParamsIsJson:(BOOL)isJson;

//取消网络请求
-(void)cancelAllTask;

//取消指定的网络Task
-(void)cancelTaskWithPort:(NSString *)port baseUrl:(NSString *)baseUrl;

//获取指定接口是否正在请求
-(void)isRequestRuningWithPort:(NSString*)port baseUrl:(NSString*)baseUrl Completed:(void (^)(BOOL isRuning))completed;

//获取对应接口的缓存
-(void)getCacheWithPort:(NSString*)port BaseUrl:(NSString*)baseUrl KeyId:(NSString*)keyId CacheBack:(void(^)(NSDictionary* retDict))cacheBack;
//清除上次缓存时间
-(void)cleanLastLimitedDateWithPort:(NSString*)port BaseUrl:(NSString*)baseUrl keyID:(NSString*)keyId;
@end
